package com.cyy.system.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cyy.common.domain.Response;
import com.cyy.common.pojo.dto.CategoryFormDto;
import com.cyy.common.pojo.dto.TagFormDto;
import com.cyy.common.pojo.query.system.SystemTagQuery;
import com.cyy.common.pojo.vo.system.SystemTagVo;
import com.cyy.common.service.TagsService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author caoyunyou
 */
@Tag(name = "标签", description = "标签")
@RestController
@RequestMapping("/system/tags")
@RequiredArgsConstructor
@SaCheckLogin
public class TagsController {

    private final TagsService tagsService;

    @GetMapping("/options")
    public Response getOptions() {
        return Response.success().data(tagsService.getOptions());
    }

    @GetMapping("/page")
    public Response getPage(SystemTagQuery query) {
        IPage<SystemTagVo> sysVo = tagsService.getPage(query);
        return Response.success().data(sysVo);
    }

    @GetMapping("/{id}/form")
    public Response getTagForm(@PathVariable("id") Integer id) {
        TagFormDto res = tagsService.getTagFormById(id);
        return Response.success().data(res);
    }

    @PostMapping("")
    public Response addTag(@RequestBody TagFormDto req) {
        tagsService.addTag(req);
        return Response.success();
    }

    @PutMapping("")
    public Response updateTag(@RequestBody TagFormDto req) {
        tagsService.updateTag(req);
        return Response.success();
    }

    @DeleteMapping("/{ids}")
    public Response deleteTags(@PathVariable("ids") String ids) {
        tagsService.deleteTags(ids);
        return Response.success();
    }
}
